package org.stvd.common.security.filter.handler;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

public class LogoutCleanCookieHandler implements LogoutHandler {

    public LogoutCleanCookieHandler() {
    }

    @Override
    public void logout(HttpServletRequest request,
            HttpServletResponse response, Authentication authentication) {
        Cookie[] cookies = request.getCookies();
        if(cookies!=null && cookies.length>0){
            for(Cookie cookie : cookies){
                cookie.setValue(null);
                cookie.setMaxAge(0);
                //cookie.setPath("/");  
                response.addCookie(cookie);  
            }
        }
    }
}